<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"/>
    <title>地图导航</title>
    <style>
        *{
            margin:0;
            padding:0px
        }
        html,
        body,
        #container {
          width: 100%;
          height: 100%;
          background-color: #ccc;
        }
    </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
    window._AMapSecurityConfig = {
      securityJsCode: "ceba8e34cf71f6d5fb16000caa70e058",
    };
</script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=c8fdda62e98d13baa5fb7b1685a04e2a"></script>
<script type="text/javascript">
    //地图初始化应该在地图容器div已经添加到DOM树之后
    var map = new AMap.Map("container", {
      zoom: 18,
      center:[114.298572, 30.584355],//中心点坐标
    });

    window.onload=function(){
        window.swift.getCurrentLocation()
    }

    //获取鸿蒙端提供的经纬度
    function getLocation(lon, lat){
        //window.swift.alert(lon+"  "+lat)
        //将地图定位到当前经纬度上
        map.setZoomAndCenter(18, [lon, lat])

        const position = new AMap.LngLat(lon, lat); //Marker 经纬度
        const marker = new AMap.Marker({
          position: position,
          content:"这是中心点",
          offset: new AMap.Pixel(-13, -30),
        });
         map.add(marker);

        // 获取附近坐标
        map.plugin(["AMap.PlaceSearch"], function () {
            const placeSearch = new AMap.PlaceSearch({
                pageSize: 4, //单页显示结果条数
                pageIndex: 1, //页码
                map:map,
                extensions: "base" //返回信息详略，默认为base（基本信息）
            });
            AMap.Event.addListener(placeSearch, "complete", (res)=>{
                window.swift.receiveData(JSON.stringify(res?.poiList?.pois||[]))
            }); //返回错误信息

            AMap.Event.addListener(placeSearch, "error", (e)=>{
                window.swift.toast("321  error:"+JSON.stringify(e))
            }); //返回错误信息
            placeSearch.searchNearBy('街道', position);
        })
    }
</script>
</body>
</html>